package com.lc.sell.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lc.sell.entity.Addresses;
import com.lc.sell.mapper.AddressesMapper;
import com.lc.sell.service.AddressesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lc.sell.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 龙晨
 * @since 2022-02-01
 */
@Service
public class AddressesServiceImpl extends ServiceImpl<AddressesMapper, Addresses> implements AddressesService {

    @Autowired
    private AddressesMapper addressesMapper;

    @Override
    @Transactional
    public ResultVo insertAddresses(Addresses addresses,String userid) {
        int i = addressesMapper.insert(addresses);
        addressesMapper.insertAU(userid, addresses.getId());
        if (i>0){
            return ResultVo.ok("添加成功");
        }
        return ResultVo.fail("添加失败");
    }

    @Override
    public ResultVo selectAddressList(String userId) {
        List<Addresses> addresses = addressesMapper.selectAddressList(userId);
        return ResultVo.ok("查询成功",addresses);
    }

    @Override
    @Transactional
    public ResultVo updateAddresses(Addresses addresses) {
        int i = addressesMapper.updateById(addresses);
        if (i>0){
            return ResultVo.ok("修改成功");
        }
        return ResultVo.fail("修改失败");
    }

    @Override
    public ResultVo selectOneAddresses(Integer id) {
        Addresses addresses = addressesMapper.selectById(id);
        return ResultVo.ok("查询成功",addresses);
    }

    @Override
    @Transactional
    public ResultVo deleteAddresses(Integer id) {
        int i = addressesMapper.deleteById(id);
        if (i>0){
            return ResultVo.ok("删除成功");
        }
        return ResultVo.fail("删除失败");
    }
}
